﻿/***************************************************************
 * 开发人员：网魂小兵@http://www.mozlite.com
 * 
 * HTML控件辅助类。
 * 
 * 最后修改：2011-10-29
 * ************************************************************/
namespace Mozlite.Web.Controls
{
    using System;
    using System.Linq;
    using System.Text;
    using System.Web.Mvc;
    using Mozlite.Common;
    using System.Web.Mvc.Html;
    using System.Linq.Expressions;
    using System.Collections.Generic;
    using Mozlite.Common.Configuration;
    using Mozlite.FileStorages;
    using System.Web.Helpers;
    using System.Web.Routing;

    /// <summary>
    /// HTML控件辅助类。
    /// </summary>
    public static class HtmlControl
    {
        #region helper
        /// <summary>
        /// 模板列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForArea<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            foreach (var areaName in Applications.LoadAreas())
            {
                items.Add(new SelectListItem { Text = areaName, Value = areaName });
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 模板列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForTheme<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            foreach (var info in ThemeConfiguration.Themes)
            {
                items.Add(new SelectListItem { Value = info.Key, Text = info.Value.Name });
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 资源列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForResource<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            foreach (var info in Resources.GetSupportLanagues())
            {
                items.Add(new SelectListItem { Value = info.Key, Text = info.Value.DisplayName });
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 域名列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="ignoreDefault">是否忽略默认选项！</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForDomain<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, bool ignoreDefault = true, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = Resources.GetString("DomainSelected"), Value = "" });
            foreach (var site in SiteDomains.LoadSites().Values)
            {
                if (ignoreDefault && site.IsDefault)
                    continue;
                items.Add(new SelectListItem { Text = site.Domain, Value = site.Domain });
            }
            return helper.DropDownListFor(expression, items, attributes);
        }
        #endregion

        #region timezone datetime format
        /// <summary>
        /// 显示时间格式列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForTimeFormat<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            var items = new List<SelectListItem>() { 
                new SelectListItem{ Value="h:m tt", Text = "12小时制，单字符 (3:8 PM)" },
	            new SelectListItem{ Value="hh:mm tt", Text = "12小时制，双字符 (03:08 PM)" },
	            new SelectListItem{ Value="H:m", Text = "24小时制，单字符 （15:8）" },
	            new SelectListItem{ Value="HH:mm", Text = "24小时制，双字符 （03:08）" },
            };
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 显示日期格式列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForDateFormat<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            var items = new List<SelectListItem>() { 
                new SelectListItem{ Text="yyyy-M-d", Value="yyyy-M-d" },
                new SelectListItem{ Text="M-d-yyyy", Value="M-d-yyyy" },
                new SelectListItem{ Text="yy-M-d", Value="yy-M-d" },
                new SelectListItem{ Text="M-d-yy", Value="M-d-yy" },
                new SelectListItem{ Text="yyyy-MM-dd", Value="yyyy-MM-dd" },
                new SelectListItem{ Text="MM-dd-yyyy", Value="MM-dd-yyyy" },
                new SelectListItem{ Text="yy-MM-dd", Value="yy-MM-dd" },
                new SelectListItem{ Text="MM-dd-yy", Value="MM-dd-yy" },
                new SelectListItem{ Text="yyyy/M/d", Value="yyyy/M/d" },
                new SelectListItem{ Text="M/d/yyyy", Value="M/d/yyyy" },
                new SelectListItem{ Text="yy/M/d", Value="yy/M/d" },
                new SelectListItem{ Text="M/d/yy", Value="M/d/yy" },
                new SelectListItem{ Text="yyyy/MM/dd", Value="yyyy/MM/dd" },
                new SelectListItem{ Text="MM/dd/yyyy", Value="MM/dd/yyyy" },
                new SelectListItem{ Text="yy/MM/dd", Value="yy/MM/dd" },
                new SelectListItem{ Text="MM/dd/yy", Value="MM/dd/yy" },
                new SelectListItem{ Text=string.Format("yyyy{0}MM{1}dd{2}", "年", "月", "日"), Value=string.Format("yyyy{0}MM{1}dd{2}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("MM{1}dd{2}yyyy{0}", "年", "月", "日"), Value=string.Format("MM{1}dd{2}yyyy{0}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("yy{0}MM{1}dd{2}", "年", "月", "日"), Value=string.Format("yy{0}MM{1}dd{2}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("MM{1}dd{2}yy{0}", "年", "月", "日"), Value=string.Format("MM{1}dd{2}yy{0}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("yyyy{0}M{1}d{2}", "年", "月", "日"), Value=string.Format("yyyy{0}M{1}d{2}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("M{1}d{2}yyyy{0}", "年", "月", "日"), Value=string.Format("M{1}d{2}yyyy{0}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("yy{0}M{1}d{2}", "年", "月", "日"), Value=string.Format("yy{0}M{1}d{2}", "年", "月", "日") },
                new SelectListItem{ Text=string.Format("M{1}d{2}yy{0}", "年", "月", "日"), Value=string.Format("M{1}d{2}yy{0}", "年", "月", "日") },
            };
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 时区列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForTimeZone<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            foreach (var info in TimeZoneInfo.GetSystemTimeZones())
            {
                items.Add(new SelectListItem { Text = info.DisplayName, Value = info.Id });
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        /// <summary>
        /// 呈现数字下拉列表框。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="begin">起始数字。</param>
        /// <param name="end">结束数字。</param>
        /// <param name="step">改变幅度。</param>
        /// <param name="firstItemText">第一个选项字符串。</param>
        /// <param name="firstItemValue">第一个选项值。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListNumberRangeFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> expression, int begin, int end, int step = 1, string textFormat = null, string firstItemText = null, int firstItemValue = 0, object attributes = null)
        {
            IList<SelectListItem> items = new List<SelectListItem>();
            if (firstItemText != null)
                items.Add(new SelectListItem { Text = firstItemText, Value = firstItemValue.ToString() });
            if (begin > end)
            {
                for (var i = begin; i >= end; i = i - step)
                {
                    items.Add(new SelectListItem { Text = (textFormat == null ? i.ToString() : string.Format(textFormat, i)), Value = i.ToString() });
                }
            }
            else
            {
                for (var i = begin; i <= end; i = i + step)
                {
                    items.Add(new SelectListItem { Text = (textFormat == null ? i.ToString() : string.Format(textFormat, i)), Value = i.ToString() });
                }
            }
            return helper.DropDownListFor(expression, items, attributes);
        }
        #endregion

        #region checkboxs
        /// <summary>
        /// 角色多选列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">Lumbda表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString CheckBoxListForRoles<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, string>> expression, ButtonFormatter formatter = ButtonFormatter.Horizontal, Dictionary<string, string> attributes = null)
        {
            List<SelectListItem> items = new List<SelectListItem>();
            foreach (var role in Roles.LoadRoles().Values)
            {
                if (role.RoleID > 0)
                    items.Add(new SelectListItem { Text = role.RoleName, Value = role.RoleID.ToString() });
            }
            return helper.CheckBoxListFor(expression, items, formatter, attributes);
        }
        ///// <summary>
        ///// 角色多选列表。
        ///// </summary>
        ///// <typeparam name="TModel">模型类型。</typeparam>
        ///// <param name="helper">Html辅助类实例对象。</param>
        ///// <param name="name">名称，控件名称。</param>
        ///// <param name="values">控件选项当前值。</param>
        ///// <param name="attributes">属性。</param>
        ///// <returns>返回呈现的字符串。</returns>
        //public static MvcHtmlString CheckboxListForRoles<TModel>(this HtmlHelper<TModel> helper, string name, string values, Dictionary<string, string> attributes = null)
        //{
        //    return helper.CheckboxListForRoles(name, values == null ? null : values.Split<int>(","), attributes);
        //}
        #endregion

        #region enum
        /// <summary>
        /// 枚举列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <param name="controller">控制器名称，主要用于资源的获取。</param>
        /// <param name="areaName">区域名称，主要用于资源的获取。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListForEnum<TModel, TProperty>(this HtmlHelper<TModel> helper, Expression<Func<TModel, TProperty>> expression, object attributes = null, string controller = null, string areaName = null)
        {
            List<SelectListItem> items = new List<SelectListItem>();
            Globals.ForEach<TProperty>(m =>
            {
                items.Add(new SelectListItem { Text = Resources.GetString(m, controller, areaName), Value = m.ToString() });
            });
            return helper.DropDownListFor(expression, items, attributes);
        }
        #endregion

        #region folders
        /// <summary>
        /// 显示用户文件夹列表。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="ignoreID">忽略的文件夹ID。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListFoldersFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> expression, int ignoreID = 0, object attributes = null)
        {
            var items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = string.Format(Resources.GetString("UCenter.DiskRoot", null, Routes.UCenter), AppContext.Current.User.NickName), Value = "0" });
            var folders = Storages.GetRootFolders();
            if (folders != null)
            {
                foreach (var folder in folders)
                {
                    if (folder.FolderID == ignoreID)
                        continue;
                    items.Add(new SelectListItem { Text = "├─" + folder.FolderName, Value = folder.FolderID.ToString() });
                    AppendSelectListItems(items, folder, 1, ignoreID);
                }
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        private static void AppendSelectListItems(List<SelectListItem> items, UserFolder folder, int level = 0, int ignoreID = 0) {
            foreach (var child in folder.Children)
            {
                if (child.FolderID == ignoreID)
                    continue;
                items.Add(new SelectListItem { Text = "├─" + "──".Times(level) + child.FolderName, Value = child.FolderID.ToString() });
                if (folder.Children != null)
                    AppendSelectListItems(items, child, level + 1, ignoreID);
            }
        }
        #endregion

        #region categories
        /// <summary>
        /// 分类下拉列表框。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="type">应用程序类型。</param>
        /// <param name="ignoreID">忽略的文件夹ID。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropdownListCategoryFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> expression, ApplicationType type, int ignoreID = 0, object attributes = null)
        {
            var items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = string.Format(Resources.GetString("Category.Root", null, Routes.ControlPanel), Resources.GetString(type)), Value = "0" });
            var categories = Categories.GetCategories(type);
            if (categories != null)
            {
                foreach (var category in categories)
                {
                    if (category.CategoryID == ignoreID)
                        continue;
                    items.Add(new SelectListItem { Text = "├─" + category.CategoryName, Value = category.CategoryID.ToString() });
                    AppendSelectListItems(items, category, 1, ignoreID);
                }
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        private static void AppendSelectListItems(List<SelectListItem> items, Category category, int level = 0, int ignoreID = 0)
        {
            foreach (var child in category.Children)
            {
                if (child.CategoryID == ignoreID)
                    continue;
                items.Add(new SelectListItem { Text = "├─" + "──".Times(level) + child.CategoryName, Value = child.CategoryID.ToString() });
                if (category.Children != null)
                    AppendSelectListItems(items, child, level + 1, ignoreID);
            }
        }
        #endregion

        #region applications
        /// <summary>
        /// 应用程序下拉列表框。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropDownListApplicationTypeFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, ApplicationType>> expression, object attributes = null)
        {
            var items = new List<SelectListItem>();
            Globals.ForEach<ApplicationType>(action => {
                items.Add(new SelectListItem { Text = Resources.GetString(action), Value = action.ToString() });
            });
            return helper.DropDownListFor(expression, items, attributes);
        }
        #endregion

        #region links
        /// <summary>
        /// AJAX链接。
        /// </summary>
        /// <param name="helper">辅助方法。</param>
        /// <param name="action">行为。</param>
        /// <param name="resourceName">资源名称。</param>
        /// <param name="postJSON">发送JSON对象。</param>
        /// <param name="htmlAttributes">元素属性。</param>
        /// <param name="areaName">区域名称。</param>
        /// <param name="callback">回调函数。</param>
        /// <param name="url">URL地址。</param>
        /// <param name="method">方法。</param>
        /// <returns>返回AJAX链接。</returns>
        public static MvcHtmlString AjaxLink(this HtmlHelper helper, HttpAction action, string resourceName, object postJSON, object htmlAttributes = null, string areaName = null, string callback = null, string url = null, string method = "POST")
        {
            TagBuilder tag = new TagBuilder("a");
            tag.MergeAttribute("href", "javascript:void(0);", true);
            var routes = new RouteValueDictionary(postJSON);
            if (routes.ContainsKey("action"))
                routes["action"] = action;
            else
                routes.Add("action", action);
            if (callback == null)
                callback = "undefined";
            if (url == null)
                url = "undefined";
            else
                url = "'" + url.JSEncode() + "'";
            tag.MergeAttribute("onclick", "return send(" + routes.ToJSON() + ", '" + method + "', " + callback + ", " + url + ");", true);
            if (htmlAttributes != null)
                tag.MergeAttributes<string, object>(new RouteValueDictionary(htmlAttributes), true);
            
            if (areaName == null)
                areaName = helper.ViewContext.GetAreaName();
            tag.SetInnerText(Resources.GetString(resourceName, null, areaName));
            return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
        }

        /// <summary>
        /// 模态窗口链接。
        /// </summary>
        /// <param name="helper">辅助方法类。</param>
        /// <param name="resourceName">资源名称。</param>
        /// <param name="url">URL地址。</param>
        /// <param name="width">宽度。</param>
        /// <param name="htmlAttributes">HTML元素。</param>
        /// <param name="areaName">区域名称。</param>
        /// <param name="resizable">是否可重置大小。</param>
        /// <param name="selector">模态元素ID。</param>
        /// <returns>返回链接字符串。</returns>
        public static MvcHtmlString ModalLink(this HtmlHelper helper, string resourceName, string url, int width, object htmlAttributes = null, string areaName = null, bool resizable = false, string selector = null)
        {
            if (selector == null)
                selector = "undefined";
            else
                selector = "'" + selector + "'";
            TagBuilder tag = new TagBuilder("a");
            tag.MergeAttribute("href", "javascript:void(0);", true);
            if (htmlAttributes != null)
                tag.MergeAttributes<string, object>(new RouteValueDictionary(htmlAttributes), true);

            tag.MergeAttribute("onclick", "return openModal('" + url.JSEncode() + "', " + width + ", " + (resizable ? "true" : "false") + ", " + selector + ");", true);
            if (areaName == null)
                areaName = helper.ViewContext.GetAreaName();
            tag.SetInnerText(Resources.GetString(resourceName, null, areaName));
            return MvcHtmlString.Create(tag.ToString(TagRenderMode.Normal));
        }

        /// <summary>
        /// 图标按钮链接。
        /// </summary>
        /// <param name="helper">辅助方法类。</param>
        /// <param name="linkText">显示字符串。</param>
        /// <param name="icon">JQuery图标名称。</param>
        /// <param name="url">URL地址。</param>
        /// <param name="isSelected">是否选中。</param>
        /// <param name="visiable">是否显示。</param>
        /// <returns>返回链接字符串。</returns>
        public static MvcHtmlString IconButtonLink(this HtmlHelper helper, string linkText, string icon, string url = null, bool isSelected = false, bool? visiable = true, object htmlAttributes = null)
        {
            if (visiable == true)
            {
                var tag = new TagBuilder("a");
                tag.MergeAttribute("href", url ?? "javascript:void(0);", true);
                tag.MergeAttribute("class", string.Format("ui-state-{0} {1}ui-button ui-widget ui-corner-all ui-button-text-icon-primary", isSelected ? "hover" : "default", isSelected ? null : "icon-button "));
                tag.MergeAttributes<string, object>(new RouteValueDictionary(htmlAttributes));
                var iconTag = new TagBuilder("span");
                iconTag.MergeAttribute("class", string.Format("ui-button-icon-primary ui-icon ui-icon-{0}", icon));
                var textTag = new TagBuilder("span");
                textTag.MergeAttribute("class", "ui-button-text");
                textTag.SetInnerText(linkText);
                tag.InnerHtml = iconTag.ToString() + textTag.ToString();
                return MvcHtmlString.Create(tag.ToString());
            } 
            return MvcHtmlString.Create(null);
        }
        #endregion

        #region navigators
        /// <summary>
        /// 论坛下拉列表框。
        /// </summary>
        /// <typeparam name="TModel">模型类型。</typeparam>
        /// <param name="helper">Html辅助类实例对象。</param>
        /// <param name="expression">表达式。</param>
        /// <param name="themeName">模板名称。</param>
        /// <param name="location">导航位置。</param>
        /// <param name="ignoreID">忽略的文件夹ID。</param>
        /// <param name="attributes">属性。</param>
        /// <returns>返回呈现的字符串。</returns>
        public static MvcHtmlString DropDownListNavigatorsFor<TModel>(this HtmlHelper<TModel> helper, Expression<Func<TModel, int>> expression, string themeName, NavigatorLocation location, int ignoreID = 0, object attributes = null)
        {
            var items = new List<SelectListItem>();
            items.Add(new SelectListItem { Text = Resources.GetString("Navigator.Root", null, Routes.ControlPanel), Value = "0" });
            ThemeConfiguration theme;
            if (ThemeConfiguration.Themes.TryGetValue(themeName, out theme))
            {
                foreach (var navigator in Navigators.GetNavigators(theme.GuidKey, location).Values)
                {
                    if (navigator.NavigatorID == ignoreID)
                        continue;
                    items.Add(new SelectListItem { Text = "├─" + navigator.DisplayName, Value = navigator.NavigatorID.ToString() });
                    AppendSelectListItems(items, navigator, 1, ignoreID);
                }
            }
            return helper.DropDownListFor(expression, items, attributes);
        }

        private static void AppendSelectListItems(List<SelectListItem> items, Navigator navigator, int level = 0, int ignoreID = 0)
        {
            foreach (var child in navigator.Children)
            {
                if (child.NavigatorID == ignoreID)
                    continue;
                items.Add(new SelectListItem { Text = "├─" + "──".Times(level) + child.DisplayName, Value = child.NavigatorID.ToString() });
                if (navigator.Children != null)
                    AppendSelectListItems(items, child, level + 1, ignoreID);
            }
        }
        #endregion
    }
}
